package com.yzd.learnjava.containers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.yzd.learnjava.util.Print;

public class Unsupported {
	static void test(String msg , List<String> list) {
		Print.print("---  " + msg + "  ---");
		Collection<String> c = list;
		Collection<String> subList = list.subList(1, 8);
		
		Collection<String> c2 = new ArrayList<String>(subList);
		
		try {
			c.retainAll(c2);
		} catch (Exception e) {
			Print.print("retainAll(): " + e); 
		}
		
		try {
			c.removeAll(c2);
		} catch (Exception e) {
			Print.print("removeAll(): " + e); 
		}
		
		try {
			c.clear();
		} catch (Exception e) {
			Print.print("clear(): " + e); 
		}
		
		try {
			c.addAll(c2);
		} catch (Exception e) {
			Print.print("addAll(): " + e); 
		}
		
		try {
			c.remove("C");
		} catch (Exception e) {
			Print.print("remove(): " + e); 
		}
		
		try {
			list.set(0,"X");
		} catch (Exception e) {
			Print.print("List.set(): " + e); 
		}
	}
	
	public static void main(String[] args) {
		List<String> list = Arrays.asList("A B C D E F G H I J K L M".split(" "));
		test("Modifiable copy", new ArrayList<String>(list));
		test("Arrays.asList()", list);
		test("unmodifiableList()", Collections.unmodifiableList(new ArrayList<String>(list)));
	}
}
